package practice1_100;

import javax.imageio.plugins.tiff.TIFFImageReadParam;
import java.util.*;

public class Wangyi {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int l1=sc.nextInt();
        int l2=sc.nextInt();
        int l3=sc.nextInt();
        Set<String> Zset=new HashSet<>();
        Set<String> Wset=new HashSet<>();
        Set<String> Bset=new HashSet<>();
        for (int i = 0; i <l1 ; i++)Zset.add(sc.next());
        for (int i = 0; i <l2 ; i++)Wset.add(sc.next());
        for (int i = 0; i <l3 ; i++)Bset.add(sc.next());
        int m=sc.nextInt();
        boolean[] res=new boolean[m];
        Arrays.fill(res,true);
        sc.nextLine();
        for (int i = 0; i < m; i++) {
            String s=sc.nextLine();
            String[] strs=s.split(" ");
            int Sub=0,verb=0,Obj=0;
            for (String ss:strs) {
                if(Zset.contains(ss)){
                    if(verb>0||Obj>0){
                        res[i]=false;
                        break;
                    }
                    ++Sub;
                }
                else if(Wset.contains(ss)){
                    if(Sub==0||verb>0){
                        res[i]=false;
                        break;
                    }
                    ++verb;
                }
                else {
                    if(Sub==0||verb==0){
                        res[i]=false;
                        break;
                    }

                }
            }
            if(verb!=1||Sub<=0) res[i]=false;

        }
    }
}
